package org.example.struct.array;

import com.alibaba.fastjson.JSON;

/**
 * @author liyishan
 * @date 2024/5/9 11:34
 * @apiNote
 */

public class Test00338CountBits {
    public static void main(String[] args) {
        int n = 2;
        int[] res = countBits(n);
        System.out.println(JSON.toJSONString(res));
    }
    public static int[] countBits(int n) {
        int[] ans = new int[n+1];
        for(int i = 0;i<=n;i++){
            int res = 0;
            int temp = i;
            while (temp != 0) {
                res += temp & 1;
                temp >>= 1;
            }
            ans[i] = res;
        }
        return ans;
    }
}


